package com.example.quickthumb;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class SettingsActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */

	private TextView tv, tv1, tv2, tv3, tv4;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);

		tv = (TextView) findViewById(R.id.sound);
		tv1 = (TextView) findViewById(R.id.music);
		tv2 = (TextView) findViewById(R.id.vibrate);
		tv3 = (TextView) findViewById(R.id.graphics);
		tv4 = (TextView) findViewById(R.id.back);

		tv.setTypeface(MainActivity.tf);
		tv1.setTypeface(MainActivity.tf);
		tv2.setTypeface(MainActivity.tf);
		tv3.setTypeface(MainActivity.tf);
		tv4.setTypeface(MainActivity.tf);

		tv.setOnTouchListener(new CustomTouchListener());
		tv1.setOnTouchListener(new CustomTouchListener());
		tv2.setOnTouchListener(new CustomTouchListener());
		tv3.setOnTouchListener(new CustomTouchListener());
		tv4.setOnTouchListener(new CustomTouchListener());

		tv.setOnClickListener(this);
		tv1.setOnClickListener(this);
		tv2.setOnClickListener(this);
		tv3.setOnClickListener(this);
		tv4.setOnClickListener(this);

		getSettings();

		setText();
		setDate();
	}

	private void setText() {
		tv.setText(settingsHolder[0] ? "Sound on" : "Sound off");
		tv1.setText(settingsHolder[1] ? "Music on" : "Music off");
		tv2.setText(settingsHolder[2] ? "Vibrate on" : "Vibrate off");
		if (!settingsHolder[3] && !settingsHolder[4]) {
			tv3.setText("LEVEL Easy");
		} else if (settingsHolder[3] && !settingsHolder[4]) {
			tv3.setText("LEVEL Medium");
		} else {
			tv3.setText("LEVEL Hard");
		}
		// tv3.setText(settingsHolder[3] ? "Gra" : "Graphics high");
	}
	
	
	private void setDate(){
//		Global.soundEnabled=settingsHolder[0];
//	Global.vibertaeEnabled=settingsHolder[2];
//		if(!settingsHolder[3]&&!settingsHolder[4])
//			Global.currentLevel=Global.EASY;
//		else if(settingsHolder[3]&&!settingsHolder[4])
//			Global.currentLevel=Global.MEDIUM;
//		else
//			Global.currentLevel=Global.HARD;
	
		}

	private boolean[] settingsHolder = new boolean[5];

	private void getSettings() {
		SharedPreferences settings = getSharedPreferences(
				MainActivity.PREFS_NAME, 0);

		settingsHolder[0] = settings.getBoolean("sound", true);
		settingsHolder[1] = settings.getBoolean("music", true);
		settingsHolder[2] = settings.getBoolean("vibrate", true);
		settingsHolder[3] = settings.getBoolean("level1", true);
		settingsHolder[4] = settings.getBoolean("level2", true);

	}

	
	@Override
	public void onClick(View v) {
		SharedPreferences settings = getSharedPreferences(
				MainActivity.PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();

		switch (v.getId()) {
		case R.id.sound:
			editor.putBoolean("sound", !settingsHolder[0]);
			break;
		case R.id.music:
			editor.putBoolean("music", !settingsHolder[1]);
			break;
		case R.id.vibrate:
			editor.putBoolean("vibrate", !settingsHolder[2]);
			break;
		case R.id.graphics:
			if (settingsHolder[4]) {
				editor.putBoolean("level1", false);
				editor.putBoolean("level2", false);
			} else if (!settingsHolder[3]) {
				editor.putBoolean("level1", true);
				editor.putBoolean("level2", false);
			} else {
				editor.putBoolean("level1", false);
				editor.putBoolean("level2", true);
			}

			break;
		case R.id.back:
			finish();
			break;
		}

		editor.commit();

		getSettings();
		setText();
		setDate();
	}
}